package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;
import com.pesking.core.util.StringUtils;

public class LeftMatchSqlParameterHandler extends SqlParameterProcessor {

	@Override
	public String getTitle() {
		return "左匹配参数";
	}

	@Override
	public String getDescription() {
		return this.getTitle() + " 在参数值的左边加通配符*";
	}

	@Override
	public void handle(StringBuilder sbSQL, Parameter parameter, List<SqlParameter> processors,SqlParameter sqlParameter) {
		String value = parameter.getParameter(sqlParameter.getName());
		if (StringUtils.isBlank(value)){
			sbSQL.append("null");
		}
		else{
			value = formatValue(value);
			sbSQL.append("'%").append(value).append("'");
		}
	}
	
	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"LV","LEFT_MATCH"});
	}
}
